//
//  ChargeTuitionViewController.m
//  家校互通
//
//  Created by 李赛 on 15/6/14.
//  Copyright (c) 2015年 姬鑫宇. All rights reserved.
//

#import "ChargeTuitionViewController.h"
#import "ChargeTuitionCollectionViewCell.h"
#import "PayViewController.h"
#import "CoModel.h"
@interface ChargeTuitionViewController ()<UICollectionViewDataSource,UICollectionViewDelegate,ConnectControlDelegate>{
    ConnectControl *connectCtr;
    NSMutableArray *paymentArray;
    UILabel *infoLB;
}

@end

@implementation ChargeTuitionViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    _contentCollectionView.delegate=self;
    _contentCollectionView.dataSource=self;
    self.title=@"收费";
    self.navigationItem.backBarButtonItem=[[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];
    
    paymentArray = [[NSMutableArray alloc]initWithCapacity:0];
    
    connectCtr = [ConnectControl showForView:self.view];
    connectCtr.delegate=self;
    
    if (connectCtr.superview!=nil && connectCtr.loading==NO)
    {
        [connectCtr setLoading:YES];
    }
    // Do any additional setup after loading the view.
}

- (void)connect{
    [CoModel getPayments:^(BOOL result, NSMutableArray *payments, NSError *error) {
        [ConnectControl removeFromView:self.view];
        paymentArray = [NSMutableArray arrayWithArray:payments];
        [_contentCollectionView reloadData];
        if (payments.count == 0) {
            infoLB = [[UILabel alloc]initWithFrame:CGRectMake(0,0,100,30)];
            infoLB.center = CGPointMake(DSF_SCREENWIDTH/2, DSF_SCREENHEIGHT/2);
            infoLB.textColor = [UIColor darkGrayColor];
            infoLB.text = @"暂无收费记录";
            infoLB.textAlignment = NSTextAlignmentCenter;
            infoLB.font = [UIFont systemFontOfSize:15.0f];
            infoLB.backgroundColor = [UIColor clearColor];
            [self.view addSubview:infoLB];
        }
    } andPageNumber:0 andPageSize:20];
}

#pragma mark---UICollectionViewDataSource--
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return paymentArray.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    Payments *model = [paymentArray objectAtIndex:indexPath.row];
    ChargeTuitionCollectionViewCell *vCell=[collectionView dequeueReusableCellWithReuseIdentifier:@"ChargeTuitionCollectionViewCell" forIndexPath:indexPath];
//    UIView *backgroundView=[[UIView alloc]initWithFrame:vCell.frame];
//    backgroundView.backgroundColor=[UIColor lightGrayColor];
//    if (indexPath.row==0) {
//        
//    }else
//    {
//        vCell.backgroundView=backgroundView;
//    }
    [vCell setContentByPayment:model];
    return vCell;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake(DSF_SCREENWIDTH, 50);
}
//- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
//{
//    HWfooterViewReusableView *footerView=[collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"HWfooterViewReusableView" forIndexPath:indexPath];
//    return footerView;
//}
#pragma mark---UICollectionViewDelegate--
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
//    AppDelegate *_appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
    Payments *model = [paymentArray objectAtIndex:indexPath.row];
    PayViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"PayViewController"];
    vc.title=@"支付";
    vc.hasPayfees=indexPath.row;
    vc.payId = model.id;
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
